package de.gwtprime.client.views;


import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

import de.gwtprime.client.ClientFactory;
import de.gwtprime.client.widgets.ArticleWidget;
import de.gwtprime.shared.requestFactory.ArticleProxy;

public class ArticleViewImpl extends Composite implements ArticleView {

	private static ArticleViewImplUiBinder uiBinder = GWT.create(ArticleViewImplUiBinder.class);
	
	interface ArticleViewImplUiBinder extends UiBinder<Widget, ArticleViewImpl>{}
	
	@UiField SimplePanel articlePanel;
	
	private Presenter presenter;
	
	private String name;

	ClientFactory clientFactory;
	
	private ArticleWidget articleWidget;
	
	public ArticleViewImpl(ClientFactory clientFactory){
		
		initWidget(uiBinder.createAndBindUi(this));
		this.clientFactory = clientFactory;
		
	}
	
	@Override
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName(){
		return name;
	}

	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;

	}
	
	public Presenter getPresenter(){
		return presenter;
	}
	
	@Override
	public void setArticle(ArticleProxy article) {
		
		articlePanel.clear();
		this.articleWidget = new ArticleWidget(article, clientFactory);
		articleWidget.setPresenter(presenter);
		articlePanel.add(articleWidget);
		
		
	}

	
	
	

}
